package example.cloudsitefeign.controller;

import example.cloudsitefeign.client.SiteManagementClient;
import example.cloudsitefeign.dto.CommonResultDTO;
import example.cloudsitefeign.dto.SiteInfoDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feign-demo") // 为这个演示Controller设置一个基础路径
public class FeignDemoController {

    private final SiteManagementClient siteManagementClient;

    // 使用构造器注入 @Autowired 在构造器上是可选的（如果只有一个构造器）
    public FeignDemoController(SiteManagementClient siteManagementClient) {
        this.siteManagementClient = siteManagementClient;
    }

    @GetMapping("/siteinfo/{id}")
    public CommonResultDTO<SiteInfoDTO> getSiteInfoViaFeign(@PathVariable("id") Long id) {
        // 通过Feign客户端调用下游服务
        return siteManagementClient.getSiteInfoById(id);
    }
}
